package com.codebo.homiematch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codebo.homiematch.common.BaseResponse;
import com.codebo.homiematch.common.ResultUtils;
import com.codebo.homiematch.model.dto.TeamDTO;
import com.codebo.homiematch.model.dto.TeamJoinRequest;
import com.codebo.homiematch.model.dto.TeamListRequest;
import com.codebo.homiematch.model.entity.Team;
import com.codebo.homiematch.model.vo.TeamVO;
import com.codebo.homiematch.service.TeamService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/team")
public class TeamController
{
    @Resource
    private TeamService teamService;

    @PostMapping("/list")
    public BaseResponse<Page<TeamVO>> getTeamList(@RequestBody TeamListRequest teamListRequest)
    {
        Page<TeamVO> teamList = teamService.getTeamList(teamListRequest);
        return ResultUtils.success(teamList);
    }

    @PostMapping("/create")
    public BaseResponse createTeam(@RequestBody TeamDTO teamDTO)
    {
        teamService.create(teamDTO);
        return ResultUtils.success(null);
    }

    @PostMapping("/join")
    public BaseResponse<Boolean> joinTeam(@RequestBody TeamJoinRequest teamJoinRequest)
    {
        boolean result = teamService.joinTeam(teamJoinRequest);
        return ResultUtils.success(result);
    }
}
